'''
同佑e生重大疾病保险产品计划
'''
import sys
sys.path.append('../..')
import json
import time
from urllib.parse import urlencode
from common.config import *
from db.mysql import MysqlClient
from itertools import product
import execjs
import requests
from common.helper import Helper



class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "老有所医"

    def genProductInfo(self):
        plan = {
            "year": [str(i) for i in range(45, 81)],
            "socialSec": ["Y", "N"],
            "deductible": ["10000", "20000"],
            "expire": ["1年"],
            "payType": ["年交"],
            "cancerMedical": ["2000000"],
            "radiationMedical": ["2000000"],
            "cancerOperation": ["2000000"],
            "cancerSerMedical": ["2000000"],
            "cancerSpeMedical": ["2000000"]
        }
        for v in product(plan["year"], plan["socialSec"], plan["deductible"], plan["expire"], plan["payType"], plan["cancerMedical"], plan["radiationMedical"], plan["cancerOperation"], plan["cancerSerMedical"], plan["cancerSpeMedical"]):
            data = Helper.formatProductInfo(plan, v)
            self.mysql.cursor.execute(
                domain[self.name]["insert_sql"].format(**data))
            self.mysql._conn.commit()
            print(domain[self.name]["insert_sql"].format(**data))
    # 执行爬虫

    def requestJson(self, dt=None, mysql=None):
        data = {
            "jsonKey": self.genSignature(dt)
        }
        payload = urlencode(data).replace("+", "")
        r = requests.post(url=domain[self.name]["url"] + payload,
                          headers=domain[self.name]["header"], data=payload)
        if r.status_code == 200:
            price = Helper.decimalParse(
                r.json()["returns"]["calRate"]["permiun"])
            data = {
                "name": self.name,
                "id": dt["id"],
                "price": price
            }
            print(data)
            mysql.updatePrice(data)
        else:
            data = {
                "name": self.name,
                "id": dt["id"],
                "state": 3
            }
            mysql.updateTask(data)
            print("\n/*产品价格信息更新失败:%d*/" % dt["id"])

    # 生成签名
    def genSignature(self, args):
        birthDate = str(2020-int(args["year"]))
        socialSec = "1" if args["socialsec"] == "Y" else "0"
        js = '''
            //生成jsonKey函数
            function genJsonKey(argument) {
                    var t = parse("t171420100302rsa")
                    , n = parse("t171420100302rsa")
                    , e = parse(argument)
                    , a = i.AES.encrypt(e, t, {
                        iv: n,
                        mode: i.mode.CBC,
                        padding: i.pad.Pkcs7
                });
                    return i.enc.Base64.stringify(a.ciphertext)
                }
            //parse函数
            function parse( e ){
                return u_parse(unescape(encodeURIComponent(e)))
            }
            //定义u_parse
            function u_parse( e ) {
                for (var n = e.length, t = [], i = 0; i < n; i++)
                    t[i >>> 2] |= (255 & e.charCodeAt(i)) << 24 - i % 4 * 8;
                return new init(t,n)
            }
            //定义init
            function init( e ) {
                if (e instanceof ArrayBuffer && (e = new Uint8Array(e)),
                (e instanceof Int8Array || "undefined" != typeof Uint8ClampedArray && e instanceof Uint8ClampedArray || e instanceof Int16Array || e instanceof Uint16Array || e instanceof Int32Array || e instanceof Uint32Array || e instanceof Float32Array || e instanceof Float64Array) && (e = new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),
                e instanceof Uint8Array) {
                    for (var t = e.byteLength, i = [], r = 0; r < t; r++)
                        i[r >>> 2] |= e[r] << 24 - r % 4 * 8;
                    n.call(this, i, t)
                } else
                    n_apply.apply(this, arguments)
            }
            //定义n_apply
            function n_apply(e, n) {
            e = this.words = e || [],
            this.sigBytes = null != n ? n : 4 * e.length
            };
            //定义encrypt
            function encrypt(t, i, r) {
                return ee(i).encrypt(n, t, i, r)
            }
            //定义ee
            function ee(e) {
                return "string" == typeof e ? w : _
            }
            //定义i对象
            var i = (function(e, n, t) {
                var i;
                return (i = i || function(e, n) {
                    var t = Object.create || function() {
                        function e() {}
                        return function(n) {
                            var t;
                            return e.prototype = n,
                            t = new e,
                            e.prototype = null,
                            t
                        }
                    }()
                    , i = {}
                    , r = i.lib = {}
                    , l = r.Base = {
                        extend: function(e) {
                            var n = t(this);
                            return e && n.mixIn(e),
                            n.hasOwnProperty("init") && this.init !== n.init || (n.init = function() {
                                n.$super.init.apply(this, arguments)
                            }
                            ),
                            n.init.prototype = n,
                            n.$super = this,
                            n
                        },
                        create: function() {
                            var e = this.extend();
                            return e.init.apply(e, arguments),
                            e
                        },
                        init: function() {},
                        mixIn: function(e) {
                            for (var n in e)
                                e.hasOwnProperty(n) && (this[n] = e[n]);
                            e.hasOwnProperty("toString") && (this.toString = e.toString)
                        },
                        clone: function() {
                            return this.init.prototype.extend(this)
                        }
                    }
                    , o = r.WordArray = l.extend({
                        init: function(e, n) {
                            e = this.words = e || [],
                            this.sigBytes = null != n ? n : 4 * e.length
                        },
                        toString: function(e) {
                            return (e || s).stringify(this)
                        },
                        concat: function(e) {
                            var n = this.words
                            , t = e.words
                            , i = this.sigBytes
                            , r = e.sigBytes;
                            if (this.clamp(),
                            i % 4)
                                for (var l = 0; l < r; l++) {
                                    var o = t[l >>> 2] >>> 24 - l % 4 * 8 & 255;
                                    n[i + l >>> 2] |= o << 24 - (i + l) % 4 * 8
                                }
                            else
                                for (var l = 0; l < r; l += 4)
                                    n[i + l >>> 2] = t[l >>> 2];
                            return this.sigBytes += r,
                            this
                        },
                        clamp: function() {
                            var n = this.words
                            , t = this.sigBytes;
                            n[t >>> 2] &= 4294967295 << 32 - t % 4 * 8,
                            n.length = e.ceil(t / 4)
                        },
                        clone: function() {
                            var e = l.clone.call(this);
                            return e.words = this.words.slice(0),
                            e
                        },
                        random: function(n) {
                            for (var t, i = [], r = function(n) {
                                var n = n
                                , t = 987654321
                                , i = 4294967295;
                                return function() {
                                    var r = ((t = 36969 * (65535 & t) + (t >> 16) & i) << 16) + (n = 18e3 * (65535 & n) + (n >> 16) & i) & i;
                                    return r /= 4294967296,
                                    (r += .5) * (e.random() > .5 ? 1 : -1)
                                }
                            }, l = 0; l < n; l += 4) {
                                var a = r(4294967296 * (t || e.random()));
                                t = 987654071 * a(),
                                i.push(4294967296 * a() | 0)
                            }
                            return new o.init(i,n)
                        }
                    })
                    , a = i.enc = {}
                    , s = a.Hex = {
                        stringify: function(e) {
                            for (var n = e.words, t = e.sigBytes, i = [], r = 0; r < t; r++) {
                                var l = n[r >>> 2] >>> 24 - r % 4 * 8 & 255;
                                i.push((l >>> 4).toString(16)),
                                i.push((15 & l).toString(16))
                            }
                            return i.join("")
                        },
                        parse: function(e) {
                            for (var n = e.length, t = [], i = 0; i < n; i += 2)
                                t[i >>> 3] |= parseInt(e.substr(i, 2), 16) << 24 - i % 8 * 4;
                            return new o.init(t,n / 2)
                        }
                    }
                    , u = a.Latin1 = {
                        stringify: function(e) {
                            for (var n = e.words, t = e.sigBytes, i = [], r = 0; r < t; r++) {
                                var l = n[r >>> 2] >>> 24 - r % 4 * 8 & 255;
                                i.push(String.fromCharCode(l))
                            }
                            return i.join("")
                        },
                        parse: function(e) {
                            for (var n = e.length, t = [], i = 0; i < n; i++)
                                t[i >>> 2] |= (255 & e.charCodeAt(i)) << 24 - i % 4 * 8;
                            return new o.init(t,n)
                        }
                    }
                    , c = a.Utf8 = {
                        stringify: function(e) {
                            try {
                                return decodeURIComponent(escape(u.stringify(e)))
                            } catch (n) {
                                throw new Error("Malformed UTF-8 data")
                            }
                        },
                        parse: function(e) {
                            return u.parse(unescape(encodeURIComponent(e)))
                        }
                    }
                    , d = r.BufferedBlockAlgorithm = l.extend({
                        reset: function() {
                            this._data = new o.init,
                            this._nDataBytes = 0
                        },
                        _append: function(e) {
                            "string" == typeof e && (e = c.parse(e)),
                            this._data.concat(e),
                            this._nDataBytes += e.sigBytes
                        },
                        _process: function(n) {
                            var t = this._data
                            , i = t.words
                            , r = t.sigBytes
                            , l = this.blockSize
                            , a = 4 * l
                            , s = r / a
                            , u = (s = n ? e.ceil(s) : e.max((0 | s) - this._minBufferSize, 0)) * l
                            , c = e.min(4 * u, r);
                            if (u) {
                                for (var d = 0; d < u; d += l)
                                    this._doProcessBlock(i, d);
                                var p = i.splice(0, u);
                                t.sigBytes -= c
                            }
                            return new o.init(p,c)
                        },
                        clone: function() {
                            var e = l.clone.call(this);
                            return e._data = this._data.clone(),
                            e
                        },
                        _minBufferSize: 0
                    })
                    , p = (r.Hasher = d.extend({
                        cfg: l.extend(),
                        init: function(e) {
                            this.cfg = this.cfg.extend(e),
                            this.reset()
                        },
                        reset: function() {
                            d.reset.call(this),
                            this._doReset()
                        },
                        update: function(e) {
                            return this._append(e),
                            this._process(),
                            this
                        },
                        finalize: function(e) {
                            e && this._append(e);
                            var n = this._doFinalize();
                            return n
                        },
                        blockSize: 16,
                        _createHelper: function(e) {
                            return function(n, t) {
                                return new e.init(t).finalize(n)
                            }
                        },
                        _createHmacHelper: function(e) {
                            return function(n, t) {
                                return new p.HMAC.init(e,t).finalize(n)
                            }
                        }
                    }),
                    i.algo = {});
                    return i
                }(Math),
                i)
            })();
            void (i.lib.Cipher || function(e) {
                    var n = i
                    , t = n.lib
                    , r = t.Base
                    , l = t.WordArray
                    , o = t.BufferedBlockAlgorithm
                    , a = n.enc
                    , s = (a.Utf8,
                    a.Base64)
                    , u = n.algo
                    , c = u.EvpKDF
                    , d = t.Cipher = o.extend({
                        cfg: r.extend(),
                        createEncryptor: function(e, n) {
                            return this.create(this._ENC_XFORM_MODE, e, n)
                        },
                        createDecryptor: function(e, n) {
                            return this.create(this._DEC_XFORM_MODE, e, n)
                        },
                        init: function(e, n, t) {
                            this.cfg = this.cfg.extend(t),
                            this._xformMode = e,
                            this._key = n,
                            this.reset()
                        },
                        reset: function() {
                            o.reset.call(this),
                            this._doReset()
                        },
                        process: function(e) {
                            return this._append(e),
                            this._process()
                        },
                        finalize: function(e) {
                            e && this._append(e);
                            var n = this._doFinalize();
                            return n
                        },
                        keySize: 4,
                        ivSize: 4,
                        _ENC_XFORM_MODE: 1,
                        _DEC_XFORM_MODE: 2,
                        _createHelper: function() {
                            function e(e) {
                                return "string" == typeof e ? w : _
                            }
                            return function(n) {
                                return {
                                    encrypt: function(t, i, r) {
                                        return e(i).encrypt(n, t, i, r)
                                    },
                                    decrypt: function(t, i, r) {
                                        return e(i).decrypt(n, t, i, r)
                                    }
                                }
                            }
                        }()
                    })
                    , p = (t.StreamCipher = d.extend({
                        _doFinalize: function() {
                            var e = this._process(!0);
                            return e
                        },
                        blockSize: 1
                    }),
                    n.mode = {})
                    , h = t.BlockCipherMode = r.extend({
                        createEncryptor: function(e, n) {
                            return this.Encryptor.create(e, n)
                        },
                        createDecryptor: function(e, n) {
                            return this.Decryptor.create(e, n)
                        },
                        init: function(e, n) {
                            this._cipher = e,
                            this._iv = n
                        }
                    })
                    , f = p.CBC = function() {
                        var n = h.extend();
                        function t(n, t, i) {
                            var r = this._iv;
                            if (r) {
                                var l = r;
                                this._iv = e
                            } else
                                var l = this._prevBlock;
                            for (var o = 0; o < i; o++)
                                n[t + o] ^= l[o]
                        }
                        return n.Encryptor = n.extend({
                            processBlock: function(e, n) {
                                var i = this._cipher
                                , r = i.blockSize;
                                t.call(this, e, n, r),
                                i.encryptBlock(e, n),
                                this._prevBlock = e.slice(n, n + r)
                            }
                        }),
                        n.Decryptor = n.extend({
                            processBlock: function(e, n) {
                                var i = this._cipher
                                , r = i.blockSize
                                , l = e.slice(n, n + r);
                                i.decryptBlock(e, n),
                                t.call(this, e, n, r),
                                this._prevBlock = l
                            }
                        }),
                        n
                    }()
                    , m = n.pad = {}
                    , b = m.Pkcs7 = {
                        pad: function(e, n) {
                            for (var t = 4 * n, i = t - e.sigBytes % t, r = i << 24 | i << 16 | i << 8 | i, o = [], a = 0; a < i; a += 4)
                                o.push(r);
                            var s = l.create(o, i);
                            e.concat(s)
                        },
                        unpad: function(e) {
                            var n = 255 & e.words[e.sigBytes - 1 >>> 2];
                            e.sigBytes -= n
                        }
                    }
                    , g = (t.BlockCipher = d.extend({
                        cfg: d.cfg.extend({
                            mode: f,
                            padding: b
                        }),
                        reset: function() {
                            d.reset.call(this);
                            var e = this.cfg
                            , n = e.iv
                            , t = e.mode;
                            if (this._xformMode == this._ENC_XFORM_MODE)
                                var i = t.createEncryptor;
                            else {
                                var i = t.createDecryptor;
                                this._minBufferSize = 1
                            }
                            this._mode && this._mode.__creator == i ? this._mode.init(this, n && n.words) : (this._mode = i.call(t, this, n && n.words),
                            this._mode.__creator = i)
                        },
                        _doProcessBlock: function(e, n) {
                            this._mode.processBlock(e, n)
                        },
                        _doFinalize: function() {
                            var e = this.cfg.padding;
                            if (this._xformMode == this._ENC_XFORM_MODE) {
                                e.pad(this._data, this.blockSize);
                                var n = this._process(!0)
                            } else {
                                var n = this._process(!0);
                                e.unpad(n)
                            }
                            return n
                        },
                        blockSize: 4
                    }),
                    t.CipherParams = r.extend({
                        init: function(e) {
                            this.mixIn(e)
                        },
                        toString: function(e) {
                            return (e || this.formatter).stringify(this)
                        }
                    }))
                    , y = n.format = {}
                    , v = y.OpenSSL = {
                        stringify: function(e) {
                            var n = e.ciphertext
                            , t = e.salt;
                            if (t)
                                var i = l.create([1398893684, 1701076831]).concat(t).concat(n);
                            else
                                var i = n;
                            return i.toString(s)
                        },
                        parse: function(e) {
                            var n = s.parse(e)
                            , t = n.words;
                            if (1398893684 == t[0] && 1701076831 == t[1]) {
                                var i = l.create(t.slice(2, 4));
                                t.splice(0, 4),
                                n.sigBytes -= 16
                            }
                            return g.create({
                                ciphertext: n,
                                salt: i
                            })
                        }
                    }
                    , _ = t.SerializableCipher = r.extend({
                        cfg: r.extend({
                            format: v
                        }),
                        encrypt: function(e, n, t, i) {
                            i = this.cfg.extend(i);
                            var r = e.createEncryptor(t, i)
                            , l = r.finalize(n)
                            , o = r.cfg;
                            return g.create({
                                ciphertext: l,
                                key: t,
                                iv: o.iv,
                                algorithm: e,
                                mode: o.mode,
                                padding: o.padding,
                                blockSize: e.blockSize,
                                formatter: i.format
                            })
                        },
                        decrypt: function(e, n, t, i) {
                            i = this.cfg.extend(i),
                            n = this._parse(n, i.format);
                            var r = e.createDecryptor(t, i).finalize(n.ciphertext);
                            return r
                        },
                        _parse: function(e, n) {
                            return "string" == typeof e ? n.parse(e, this) : e
                        }
                    })
                    , z = n.kdf = {}
                    , C = z.OpenSSL = {
                        execute: function(e, n, t, i) {
                            i || (i = l.random(8));
                            var r = c.create({
                                keySize: n + t
                            }).compute(e, i)
                            , o = l.create(r.words.slice(n), 4 * t);
                            return r.sigBytes = 4 * n,
                            g.create({
                                key: r,
                                iv: o,
                                salt: i
                            })
                        }
                    }
                    , w = t.PasswordBasedCipher = _.extend({
                        cfg: _.cfg.extend({
                            kdf: C
                        }),
                        encrypt: function(e, n, t, i) {
                            var r = (i = this.cfg.extend(i)).kdf.execute(t, e.keySize, e.ivSize);
                            i.iv = r.iv;
                            var l = _.encrypt.call(this, e, n, r.key, i);
                            return l.mixIn(r),
                            l
                        },
                        decrypt: function(e, n, t, i) {
                            i = this.cfg.extend(i),
                            n = this._parse(n, i.format);
                            var r = i.kdf.execute(t, e.keySize, e.ivSize, n.salt);
                            i.iv = r.iv;
                            var l = _.decrypt.call(this, e, n, r.key, i);
                            return l
                        }
                    })
                }())
            function ac(e, n, t) {
                
                return (function() {
                    var e = i
                    , n = e.lib.BlockCipher
                    , t = e.algo
                    , r = []
                    , l = []
                    , o = []
                    , a = []
                    , s = []
                    , u = []
                    , c = []
                    , d = []
                    , p = []
                    , h = [];
                    !function() {
                        for (var e = [], n = 0; n < 256; n++)
                            e[n] = n < 128 ? n << 1 : n << 1 ^ 283;
                        var t = 0
                        , i = 0;
                        for (n = 0; n < 256; n++) {
                            var f = i ^ i << 1 ^ i << 2 ^ i << 3 ^ i << 4;
                            f = f >>> 8 ^ 255 & f ^ 99,
                            r[t] = f,
                            l[f] = t;
                            var m = e[t]
                            , b = e[m]
                            , g = e[b]
                            , y = 257 * e[f] ^ 16843008 * f;
                            o[t] = y << 24 | y >>> 8,
                            a[t] = y << 16 | y >>> 16,
                            s[t] = y << 8 | y >>> 24,
                            u[t] = y,
                            y = 16843009 * g ^ 65537 * b ^ 257 * m ^ 16843008 * t,
                            c[f] = y << 24 | y >>> 8,
                            d[f] = y << 16 | y >>> 16,
                            p[f] = y << 8 | y >>> 24,
                            h[f] = y,
                            t ? (t = m ^ e[e[e[g ^ m]]],
                            i ^= e[e[i]]) : t = i = 1
                        }
                    }();
                    var f = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]
                    , m = t.AES = n.extend({
                        _doReset: function() {
                            if (!this._nRounds || this._keyPriorReset !== this._key) {
                                for (var e = this._keyPriorReset = this._key, n = e.words, t = e.sigBytes / 4, i = 4 * ((this._nRounds = t + 6) + 1), l = this._keySchedule = [], o = 0; o < i; o++)
                                    if (o < t)
                                        l[o] = n[o];
                                    else {
                                        var a = l[o - 1];
                                        o % t ? t > 6 && o % t == 4 && (a = r[a >>> 24] << 24 | r[a >>> 16 & 255] << 16 | r[a >>> 8 & 255] << 8 | r[255 & a]) : (a = r[(a = a << 8 | a >>> 24) >>> 24] << 24 | r[a >>> 16 & 255] << 16 | r[a >>> 8 & 255] << 8 | r[255 & a],
                                        a ^= f[o / t | 0] << 24),
                                        l[o] = l[o - t] ^ a
                                    }
                                for (var s = this._invKeySchedule = [], u = 0; u < i; u++)
                                    o = i - u,
                                    a = u % 4 ? l[o] : l[o - 4],
                                    s[u] = u < 4 || o <= 4 ? a : c[r[a >>> 24]] ^ d[r[a >>> 16 & 255]] ^ p[r[a >>> 8 & 255]] ^ h[r[255 & a]]
                            }
                        },
                        encryptBlock: function(e, n) {
                            this._doCryptBlock(e, n, this._keySchedule, o, a, s, u, r)
                        },
                        decryptBlock: function(e, n) {
                            var t = e[n + 1];
                            e[n + 1] = e[n + 3],
                            e[n + 3] = t,
                            this._doCryptBlock(e, n, this._invKeySchedule, c, d, p, h, l),
                            t = e[n + 1],
                            e[n + 1] = e[n + 3],
                            e[n + 3] = t
                        },
                        _doCryptBlock: function(e, n, t, i, r, l, o, a) {
                            for (var s = this._nRounds, u = e[n] ^ t[0], c = e[n + 1] ^ t[1], d = e[n + 2] ^ t[2], p = e[n + 3] ^ t[3], h = 4, f = 1; f < s; f++) {
                                var m = i[u >>> 24] ^ r[c >>> 16 & 255] ^ l[d >>> 8 & 255] ^ o[255 & p] ^ t[h++]
                                , b = i[c >>> 24] ^ r[d >>> 16 & 255] ^ l[p >>> 8 & 255] ^ o[255 & u] ^ t[h++]
                                , g = i[d >>> 24] ^ r[p >>> 16 & 255] ^ l[u >>> 8 & 255] ^ o[255 & c] ^ t[h++]
                                , y = i[p >>> 24] ^ r[u >>> 16 & 255] ^ l[c >>> 8 & 255] ^ o[255 & d] ^ t[h++];
                                u = m,
                                c = b,
                                d = g,
                                p = y
                            }
                            m = (a[u >>> 24] << 24 | a[c >>> 16 & 255] << 16 | a[d >>> 8 & 255] << 8 | a[255 & p]) ^ t[h++],
                            b = (a[c >>> 24] << 24 | a[d >>> 16 & 255] << 16 | a[p >>> 8 & 255] << 8 | a[255 & u]) ^ t[h++],
                            g = (a[d >>> 24] << 24 | a[p >>> 16 & 255] << 16 | a[u >>> 8 & 255] << 8 | a[255 & c]) ^ t[h++],
                            y = (a[p >>> 24] << 24 | a[u >>> 16 & 255] << 16 | a[c >>> 8 & 255] << 8 | a[255 & d]) ^ t[h++],
                            e[n] = m,
                            e[n + 1] = b,
                            e[n + 2] = g,
                            e[n + 3] = y
                        },
                        keySize: 8
                    });
                    e.AES = n._createHelper(m)
                }(),
                i.AES)
            }
            function ae(e, n, t) {
                return (
                l = (r = i).lib.WordArray,
                r.enc.Base64 = {
                    stringify: function(e) {
                        var n = e.words
                        , t = e.sigBytes
                        , i = this._map;
                        e.clamp();
                        for (var r = [], l = 0; l < t; l += 3)
                            for (var o = (n[l >>> 2] >>> 24 - l % 4 * 8 & 255) << 16 | (n[l + 1 >>> 2] >>> 24 - (l + 1) % 4 * 8 & 255) << 8 | n[l + 2 >>> 2] >>> 24 - (l + 2) % 4 * 8 & 255, a = 0; a < 4 && l + .75 * a < t; a++)
                                r.push(i.charAt(o >>> 6 * (3 - a) & 63));
                        var s = i.charAt(64);
                        if (s)
                            for (; r.length % 4; )
                                r.push(s);
                        return r.join("")
                    },
                    parse: function(e) {
                        var n = e.length
                        , t = this._map
                        , i = this._reverseMap;
                        if (!i) {
                            i = this._reverseMap = [];
                            for (var r = 0; r < t.length; r++)
                                i[t.charCodeAt(r)] = r
                        }
                        var o = t.charAt(64);
                        if (o) {
                            var a = e.indexOf(o);
                            -1 !== a && (n = a)
                        }
                        return function(e, n, t) {
                            for (var i = [], r = 0, o = 0; o < n; o++)
                                if (o % 4) {
                                    var a = t[e.charCodeAt(o - 1)] << o % 4 * 2
                                    , s = t[e.charCodeAt(o)] >>> 6 - o % 4 * 2;
                                    i[r >>> 2] |= (a | s) << 24 - r % 4 * 8,
                                    r++
                                }
                            return l.create(i, r)
                        }(e, n, i)
                    },
                    _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
                },
                i.enc.Base64)
            }
            ae ()
            ac()
        '''
        cxt = execjs.compile(js)
        argument = '{"body":{"commodityCombinationId":"31","birthDate":"'+birthDate+'0101","guaranteeTerm":"1","insuredAmount":"","underwritingProfession":"","crowdSuits":"","counts":"1","socialInsurance":"'+socialSec + \
            '","deductibleExcess":"'+args["deductible"]+'","versions":""},"head":{"userCode":null,"channelCode":"101","transTime":"'+str(
                int(time.time())*1000)+'","transToken":"","customerId":null,"transSerialNumber":""}}'
        signature = cxt.call("genJsonKey", argument)
        return signature
